import React, { Component } from 'react'
import { withRouter } from 'react-router-dom'
import './search_item.less'
class SearchItem extends Component {
  goReult = (id, searchType) => {
    return () => {
      if (searchType == 1) {
        this.props.history.push({
          pathname: '/course-detail',
          search:'courseId='+id
        })
      } else if (searchType == 2) {
        this.props.history.push({
          pathname: '/blog-detail',
          search:'blogId='+id
        })
      }else{
        this.props.history.push("/resource")
      }
    }
  }
  render() {
    const { id, title, description, searchType } = this.props
    return (
      <div className="search-item-container" onClick={this.goReult(id, searchType)}>
        <div className="left-search">
          <h2>{title}</h2>
          <p>{description}</p>
        </div>
        <div className="right-search">
          {searchType == 1 ? '课程' : searchType == 2 ? '文章' : '资源'}
        </div>
      </div>
    )
  }
}
export default withRouter(SearchItem)
